<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i> 属性修改</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post" action="" data-validate="validate">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理员账号</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" placeholder="管理员账号" name="username" disabled>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">管理员名称</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" placeholder="管理员名称" name="name">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">手机号</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" placeholder="手机号" name="phone">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">密码</label>
                                            <div class="col-sm-9">
                                                <input type="password" class="form-control" placeholder="密码" name="password">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">确认密码</label>
                                            <div class="col-sm-9">
                                                <input type="password" class="form-control" placeholder="密码" name="repassword">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">状态:</label>
                                            <div class="col-sm-9">
                                                <select class="form-control" name="state" id="state">
                                                    <option value="-1">非正常</option>
                                                    <option value="1">正常</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>


<script>
    function validate($from) {

        var name = $from.find('input[name="name"]');
        if ($.trim(name.val()) == '') {
            return '名称不能为空';
        }
        var phone = $from.find('input[name="phone"]');
        if ($.trim(phone.val()) == '') {
            return '手机不能为空';
        }
        if(!isPhoneNo(phone.val())){
            return '非法的手机号';
        }
        var password = $from.find('input[name="password"]');
        if ($.trim(password.val()) != '') {
            if ($.trim(password.val()).length<6) {
                return '密码不能小于6位';
            }
            var repassword = $from.find('input[name="repassword"]');
            if(password.val()!=repassword.val()){
                return '两次密码不相同';
            }
        }
        return true;
    }

    $(document).ready(function () {
        $("form").attr("action", common_conf.requestUrl+'managerUser/edit');
        getManagerUserDetail($.getUrlVar('id'));
    });

    function getManagerUserDetail(id) {
        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'managerUser/detail',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: '{"id":'+id+'}',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                if(forceLogin(returnData)) return;
                var obj=returnData;
                if(obj.state=="success"){
                    initFormData(obj.data);
                }else{
                    alert("获取失败");
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

    function initFormData($manageruser) {
        $("input[name='username']").val($manageruser.username);
        $("input[name='name']").val($manageruser.name);
        $("input[name='phone']").val($manageruser.phone);
        $("#state option[value='"+$manageruser.state+"']").attr("selected","selected");
        $('form').append("<input type='hidden' name='id' value='"+$manageruser.id+"'>");
    }
</script>